package com.sx.gongzhong.activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.sx.gongzhong.BaseActivity;
import com.sx.gongzhong.R;
import com.sx.gongzhong.adapter.MainPageEntranceAdapter;
import com.sx.gongzhong.model.EntranceBean;
import com.sx.gongzhong.widget.MyPopupWindow;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 更多
 * Created by admin on 2017/12/28.
 */

public class MoreEntranceActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.gv)
    GridView gv;
    private MyPopupWindow selectPop;

    String[] names = new String[]{"便民公告", "便民诉求", "全民护路", "办事指南",
            "法律咨询","信访举报",  "平安宣传", "互帮互助"};
    int[] icons = new int[]{R.mipmap.icon_announcement, R.mipmap.icon_appeal_more, R.mipmap.icon_mow, R.mipmap.icon_guide,
            R.mipmap.icon_law, R.mipmap.icon_letterinquiring, R.mipmap.icon_propaganda,R.mipmap.icon_help};

    private MainPageEntranceAdapter adapter;

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_more_entrance);
        ButterKnife.bind(this);
        setTitleName("更多");
        ArrayList<EntranceBean> list = new ArrayList<EntranceBean>();
        for (int i = 0; i < names.length; i++) {
            EntranceBean serviceBean = new EntranceBean();
            serviceBean.icon = icons[i];
            serviceBean.name = names[i];
            list.add(serviceBean);
        }
        adapter = new MainPageEntranceAdapter(this, R.layout.adapter_item_entrance, list);
        gv.setAdapter(adapter);
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0://便民公告
                        startActivity(new Intent(MoreEntranceActivity.this,ConvenniceAnnounceActivity.class));
                        break;
                    case 1://便民诉求
                        startActivity(new Intent(MoreEntranceActivity.this, ConvenniceAppealActivity.class));
                        break;
                    case 2://全民护路
                        startActivity(new Intent(MoreEntranceActivity.this,DefendRoadActivity.class));
                        break;
                    case 3://办事指南
                        startActivity(new Intent(MoreEntranceActivity.this,GuidanceActivity.class));
                        break;
                    case 4://法律咨询
                        startActivity(new Intent(MoreEntranceActivity.this,LegalAdviceActivity.class));
                        break;
                    case 5://信访举报
                        showPopupSelect();
                        break;
                    case 6://平安宣传
                        startActivity(new Intent(MoreEntranceActivity.this,PromotePeaceActivity.class));
                        break;
                    case 7://互帮互助
                        startActivity(new Intent(MoreEntranceActivity.this,HelpActivity.class));
                        break;
                }
            }
        });
    }

    /**
     * 显示选择文件的弹窗
     */
    private void showPopupSelect() {
        if (selectPop == null) {
            View view = LayoutInflater.from(this).inflate(R.layout.pop_select_file, null);
            selectPop = new MyPopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            selectPop.setTouchable(true);
            selectPop.setOutsideTouchable(false);
            selectPop.setBackgroundDrawable(new ColorDrawable(Color.alpha(128)));
            view.findViewById(R.id.tv_String).setOnClickListener(this);
            view.findViewById(R.id.tv_Picture).setOnClickListener(this);
            view.findViewById(R.id.tv_Audio).setOnClickListener(this);
            view.findViewById(R.id.tv_Video).setOnClickListener(this);
            view.findViewById(R.id.tv_Cancel).setOnClickListener(this);
        }
        selectPop.showAsDropDown(findViewById(R.id.toolbar));
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.tv_Cancel){
            selectPop.dismiss();
            return;
        }
        int type=0;
        switch (v.getId()){
            case R.id.tv_String:
                type=0;
                break;
            case R.id.tv_Picture:
                type=1;
                break;
            case R.id.tv_Audio:
                type=2;
                break;
            case R.id.tv_Video:
                type=3;
                break;
        }
        selectPop.dismiss();
        startActivity(new Intent(MoreEntranceActivity.this,ReportActivity.class)
        .putExtra("TYPE",type));
    }
}
